
import VolunteerAPI from '../api/volunteer.js';

export const Volunteer={
   state:{
      volunteerlist:[],
      volunteer_total_count:0,
      editVolunteerStatus:-1,     //插入状态 0失败  1成功  -1不改变
      volunteerinfo:[],
      delVolunteerStatus:-1,       //删除状态
      volunteersignlist:[]         //报名列表
   },
   mutations:{
      setVolunteerList(state,list){
          state.volunteerlist=list;
      },
      setVolunteerTotalCount(state,total_count){
          state.volunteer_total_count=total_count;
      },
      setEditVolunteerStatus(state,status){
          state.editVolunteerStatus=status;
      },
      setVolunteerInfo(state,info){
          state.volunteerinfo=info;
      },
      setDelVolunteerStatus(state,status){
          state.delVolunteerStatus=status;
      },
      setVolunteerSignList(state,list){
          state.volunteersignlist=list;
      }
   },
   actions:{
      loadVolunteerList(context,data){
          VolunteerAPI.getVolunteerList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setVolunteerList',response.data.list);
                  context.commit('setVolunteerTotalCount',response.data.total_count);
              }
          })
      },
      //插入Volunteer
      editVolunteer(context,data){
          VolunteerAPI.editVolunteer(data).then(function(response){
              context.commit('setEditVolunteerStatus',response.data.code);
          })
      },
      //获取详情
      loadVolunteerInfo(context,data){
          VolunteerAPI.getVolunteerInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setVolunteerInfo',response.data.info);
              }
          })
      },
      //删除
      delVolunteer(context,data){
          VolunteerAPI.delVolunteer(data).then(function(response){
                context.commit('setDelVolunteerStatus',response.data.code);
          })
      },
      loadVolunteerSignList(context,data){
         VolunteerAPI.getVolunteerSignList(data).then(function(response){
                context.commit('setVolunteerSignList',response.data.list);
         })
      }
   },
   getters:{
      getVolunteerList:state =>{
         return state.volunteerlist
      },
      getVolunteerTotalCount: state =>{
         return state.volunteer_total_count
      },
      getEditVolunteerStatus:state=>{
          return state.editVolunteerStatus;
      },
      getVolunteerInfo:state => {
          return state.volunteerinfo;
      },
      getDelVolunteerStatus:state => {
          return state.delVolunteerStatus;
      },
      getVolunteerSignList:state =>{
          return state.volunteersignlist;
      }
   }
}
